#!/bin/sh

## 应用选项
APP_NAME=community

APP_PORT=8200

## 检查进程是否存在
PID=$(ps -ef | grep -w "$APP_NAME" | grep -w "java"| grep -w "$APP_PORT" | grep -v "grep" | awk '{print $2}')
if [ "$PID" == "" ]; then
	echo "应用：$APP_NAME 端口：$APP_PORT 进程不存在。"
else
	echo "应用：$APP_NAME 端口：$APP_PORT 存在进程：$PID"
	kill -15 $PID
	sleep 3
	## 如果仍然存在则强行停止
	CHECK_PID=$(ps -ef | grep -w "$APP_NAME" | grep -w "java"| grep -w "$APP_PORT" | grep -v "grep" | awk '{print $2}')
	if [ "$CHECK_PID" == "" ]; then
		echo "应用：$APP_NAME 端口：$APP_PORT 进程：$PID 停止成功。"
	else
		echo "应用：$APP_NAME 端口：$APP_PORT 进程：$PID 强行停止！"
		kill -9 $PID
	fi
fi

exit 0

